package javaweb.selectcclass.test.entity;

import lombok.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

import javax.persistence.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

@Getter
@Setter
@NoArgsConstructor//如果force了就持续为null
@AllArgsConstructor
@Entity
@Table(name = "stu_user")
public class User implements UserDetails {
//    姓名、学号、年级、专业、学院
    private String name;
    @Id
    private String stuId;
    private String pwd;
    private String grade;
    private String major;
    private String academy;
    @ManyToMany
    @JoinTable(name = "user_select")
    private List<Course> courses;

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", stuId='" + stuId + '\'' +
                ", pwd='" + pwd + '\'' +
                ", grade='" + grade + '\'' +
                ", major='" + major + '\'' +
                ", academy='" + academy + '\'' +
                ", courses=" + courses +
                '}';
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"));
    }

    @Override
    public String getPassword() {
        return pwd;
    }

    @Override
    public String getUsername() {
        return stuId;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
